const graph = require('./graph');

//用集合来记录当前访问节点的子节点是否已经被访问过
const visited = new Set();
const dfs = (n) => {
    console.log(n);
    visited.add(n);
    graph[n].forEach(c => {
        if (!visited.has(c)){
            dfs(c);
        }
    });
};

//传入根节点的值
dfs(2);